package com.lwj.liwanjia.view.fragment.myindent;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.adapter.indent.OrderAdapter;
import com.lwj.liwanjia.adapter.indent.UnOrderAdapter;
import com.lwj.liwanjia.base.LazyFragment;
import com.lwj.liwanjia.view.activity.myindent.BgUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.BjUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.BuyUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.DjUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.DyUndorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.JdUnorederDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.KdUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.KfUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.LyUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.QuUnorderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.SeatUnoderDetailActivity;
import com.lwj.liwanjia.view.activity.myindent.SendUnorderDetailActivity;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;
import com.superrecycleview.superlibrary.recycleview.SuperRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 已接单
 */
public class OrderFragment extends LazyFragment {

    /**
     * 待改成和待付款一样的布局
     */
    @BindView(R.id.order_rlv)
    SuperRecyclerView orderRlv;

    // 标志位，标志已经初始化完成。
    private boolean isPrepared;
    private List<String> list = new ArrayList<>();
    private OrderAdapter orderAdapter;

    @Override
    protected void lazyLoad() {
        if (!isPrepared || !isVisible) {
            return;
        }
        initData();
    }

    private void initData() {
        list.clear();
        list.add("0");
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        list.add("7");
        list.add("8");
        list.add("9");
        list.add("10");
        list.add("11");
        list.add("12");
        list.add("13");
        orderAdapter.notifyDataSetChanged();
    }

    @Override
    protected void initView() {
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        orderRlv.setLayoutManager(manager);
        orderRlv.setRefreshEnabled(false);
        orderRlv.setLoadMoreEnabled(false);
        orderAdapter = new OrderAdapter(getActivity(), list, false);
        orderRlv.setAdapter(orderAdapter);
        listener();
        isPrepared = true;
        lazyLoad();
    }

    private void listener() {
        orderAdapter.setOnItemClickListener(new SuperBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, Object item, int position) {
                if (list.get(position).equals("13")) {//搬家
                    Intent i = new Intent(getActivity(), BjUnorderDetailActivity.class);
                    i.putExtra("type", "已接单");
                    startActivity(i);
                } else if (list.get(position).equals("1")) {//景区
                    Intent i = new Intent(getActivity(), LyUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                } else if (list.get(position).equals("0")) {//导游
                    Intent i = new Intent(getActivity(), DyUndorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                } else if (list.get(position).equals("6")) {//宾馆
                    Intent i = new Intent(getActivity(), BgUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                }else if (list.get(position).equals("7")) {//看房
                    Intent i = new Intent(getActivity(), KfUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                }else if (list.get(position).equals("9")) {//酒店
                    Intent i = new Intent(getActivity(), JdUnorederDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                } else if (list.get(position).equals("11")) {//司机滴滴（预约今天）
                    Intent i = new Intent(getActivity(), DjUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    i.putExtra("type1", "7");
                    startActivity(i);
                } else if (list.get(position).equals("12")) {//司机滴滴（预约明天）
                    Intent i = new Intent(getActivity(), DjUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    i.putExtra("type1", "6");
                    startActivity(i);
                }else if (list.get(position).equals("8") ) {//预定座位（包间）
                    Intent i = new Intent(getActivity(), SeatUnoderDetailActivity.class);
                    i.putExtra("type","已接单");
                    i.putExtra("type1","1");
                    startActivity(i);
                }else if(list.get(position).equals("2")){//帮我送
                    Intent i = new Intent(getActivity(),SendUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                }else if(list.get(position).equals("3")){//帮我取
                    Intent i = new Intent(getActivity(),QuUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                }else if(list.get(position).equals("4")){//帮我买
                    Intent i = new Intent(getActivity(),BuyUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                }else if(list.get(position).equals("5")){//快递
                    Intent i = new Intent(getActivity(),KdUnorderDetailActivity.class);
                    i.putExtra("type","已接单");
                    startActivity(i);
                }
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_order;
    }

}
